<div class="container">
    <div class="row">
        <div class="span12">
            <div id="alert-area">
                
            </div>
        </div>
    </div>
    <div class="row">
        <div id="show" class="span12">
            <form class="form-search">
                <input type="text" id="q"/>
                <select name="field" id="field">
                    <option value="username">Username</option>
                    <option value="nama">Nama</option>
                    <option value="aktif">Aktif</option>
                </select>
                <a href="#" class="btn btn-primary" id="search">Search</a>
            </form>
            <div id="table">
            <?php
            switch($fetch_type){
                case 'boss':
                    $this->load->view('user/showboss');
                    $usertype = 'boss';
                    break;
                case 'pegawai1':
                    $this->load->view('user/showpegawai1');
                    $usertype = 'pegawai1';
                    break;
                case 'pegawai2':
                    $this->load->view('user/showpegawai2');
                    $usertype = 'pegawai2';
                    break;
            }
            ?>
            </div>
            <a href="<?php echo site_url('admin/input/'.$usertype) ?>" id="input" class="btn btn-primary fancybox fancybox.iframe input">Input New</a>
        </div>
    </div>
</div>
<script type="text/javascript">
    $("#search").click(function(){
        type = "<?php echo $fetch_type; ?>";
        q = $("#q").val();
        field = $("#field").val();
        
    if(q == ""){
        alert('Isi textbox terlebih dahulu');
    }else{
        console.log('test');
        switch(type){
            case 'boss':
                $.post("<?php echo site_url('admin/search/boss'); ?>", { q:q, field:field }, function(data){
                    $('#table').html(data);
                });
                break;
            case 'pegawai1':
                $.post("<?php echo site_url('admin/search/pegawai1'); ?>", { q:q, field:field }, function(data){
                    $('#table').html(data);
                });
                break;
            case 'pegawai2':
                $.post("<?php echo site_url('admin/search/pegawai2'); ?>", { q:q, field:field }, function(data){
                    $('#table').html(data);
                });
                break;
            }
        }
        
    });
    
    function alertz (type, heading, message, usertype) {
        parent.$.fancybox.close();
        switch(usertype){
            case 'boss':
                $.get('<?php echo site_url('admin/refresh/boss'); ?>', function(data) {
                    $('#table').html(data);
                });
                break;
            case 'pegawai1':
                $.get('<?php echo site_url('admin/refresh/pegawai1'); ?>', function(data) {
                    $('#table').html(data);
                });
                break;
            case 'pegawai2':
                $.get('<?php echo site_url('admin/refresh/pegawai2'); ?>', function(data) {
                    $('#table').html(data);
                });
                break;
            }
            $("#alert-area").append($("<div class='alert-message alert alert-block " + type + " fade in' data-alert><a class='close' data-dismiss='alert' href='#'>&times;</a><h4 class='alert-heading'>"+ heading +"</h4><p> " + message + " </p></div>"));
            $(".alert-message").delay(1000).fadeOut("slow", function () { $(this).remove(); });
        }
</script>

